import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/layout'
import dashboard from '@/views/dashboard'

/** 导入动态路由 */
import agents from './modules/agents.js'
import categories from './modules/categories'
import client from './modules/client'
import employees from './modules/employees'
import pages from './modules/pages'
import permissions from './modules/permissions.js'
import property from './modules/property.js'
import roles from './modules/roles.js'

Vue.use(VueRouter)

/** 动态路由 */
export const asyncRoutes = [categories, pages, agents, client, property, permissions, roles, employees]

/** 静态路由 */
const constRoutes = [
  {
    path: '/',
    component: layout,
    redirect: '/dashboard',
    children: [{
      path: '/dashboard',
      component: dashboard,
      /** 用于渲染侧边栏, icon 的值为svg文件名，也可以使用element-ui的类名，例如 el-icon-user */
      meta: {
        title: '首页管理',
        icon: 'dashboard'
        // icon: 'el-icon-user'
      }
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/register',
    component: () => import('@/views/register/index.vue')
  }
]


const createRouter = () => new VueRouter({
  routes: [...constRoutes]
})


const router = createRouter()
// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
